import request from '@/utils/request'
import type { loginFormData, loginResponseData, Infodata, RegisterResponseData } from './type'
import qs from 'qs'


export function reqLogin(data: loginFormData): Promise<loginResponseData> {
  const url = '/api/login';
  return request({
    url: url,
    method: 'post',
    data: qs.stringify(data), // 将对象转换为URL编码的字符串
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded', // 设置请求头
    },
  });
}
// export const reqLogin = (data: loginFormData) => request.post<any, loginResponseData>('/api/login', qs.stringify(data))
export function reqUserInfo() : Promise<Infodata>{
  const url = `/api/getInfo`
  return request({
    url: url,
    method: 'get'
  })
}

export function reqregister(data:loginFormData):Promise<RegisterResponseData>{
  const url = '/api/register'
  return request({
    url: url,
    method: 'post',
    data: qs.stringify(data),
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    }
  })
}

export function reqLogout():Promise<RegisterResponseData> {
  const url = '/api/logout'
  return request({
    url: url,
    method: 'post'
  })
}

export function modifypwd(data:any) {
  return request({
      url: '/api/modifypwd',
      method: 'post',
      data: qs.stringify(data),
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
      }
  })
}